package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.Note;
import cn.wolfcode.wolf2w.business.mapper.NoteMapper;
import cn.wolfcode.wolf2w.business.query.NoteQuery;
import cn.wolfcode.wolf2w.business.service.INoteService;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.member.api.RemoteUserInfoService;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 旅游日记Service业务层处理
 * 
 * @author 沙琪玛
 * @date 2024-11-01
 */
@Service
@Transactional
public class NoteServiceImpl extends ServiceImpl<NoteMapper,Note> implements INoteService {

    @Autowired
    private RemoteUserInfoService userInfoService;

    @Override
    public IPage<Note> queryPage(NoteQuery qo) {
        IPage<Note> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());

        LambdaQueryWrapper<Note> queryWrapper = new LambdaQueryWrapper<>();

        IPage<Note> pageResult = baseMapper.selectPage(page, queryWrapper);

        for (Note note : pageResult.getRecords()) {
            Long authorId = note.getAuthorId();
            R<UserInfo> r = userInfoService.getOne(authorId, "inner");
            UserInfo userinfo = r.getData();
            note.setAuthor(userinfo);
        }
        return  pageResult;
    }
}
